package com.atguigu.atcrowdfunding.controller;

import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.atguigu.atcrowdfunding.bean.TProject;
import com.atguigu.atcrowdfunding.service.TProjectService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Controller
@RequestMapping("/auth_project")
public class AuthProjectController {

	@Autowired
	TProjectService projectService;
	
	Logger log = LoggerFactory.getLogger(this.getClass());
	
	@GetMapping("/index")
	public String index(@RequestParam(value="pageNum",required=false,defaultValue="1") Integer pageNum,
			@RequestParam(value="pageSize",required=false,defaultValue="10") Integer pageSize,
			Model model,
			@RequestParam(value="condition",required=false,defaultValue="") String condition) {
		log.debug("pageNum={}",pageNum);
		log.debug("pageSize={}",pageSize);
		log.debug("condition={}",condition);
//		线程绑定
		PageHelper.startPage(pageNum, pageSize);
		Map<String,Object> paramMap = new HashMap<String, Object>();
		
		paramMap.put("condition", condition);
		
		PageInfo<TProject> page = projectService.listUnauthProjectPage(paramMap);
		model.addAttribute("page",page);
		return "auth_project/index";
	}
	
	@GetMapping("/auth")
	public String auth(Integer id,Integer pageNum) {
		projectService.authProject(id);
		return "redirect:/auth_project/index?pageNum="+pageNum;
	}
	
	
}
